/**
 * @description: 仓库接口
 */
import { postRequest, getRequest, getDownload, uploadRequest } from '@/lib/axios'

// 仓库
interface WarehouseApi {
  queryList: (params?: any) => Promise<any>
  create: (params: any) => Promise<any>
  update: (params: any) => Promise<any>
  delete: (ids: string) => Promise<any>
  listAmount: (params?: any) => Promise<any>
  checkDriver: (params: any) => Promise<any>
}

export const warehouseApi: WarehouseApi = {
  // 仓库列表
  queryList: (param) => {
    return getRequest('/warehouse/list', param)
  },

  // 仓库新增
  create: (params) => {
    return postRequest('/warehouse/add', params)
  },

  // 仓库编辑
  update: (params) => {
    return postRequest('/warehouse/edit', params)
  },

  // 仓库删除
  delete: (id: string) => {
    return postRequest(`/warehouse/del`, { id })
  },
  // 仓库总计
  listAmount: (param) => {
    return getRequest(`/warehouse/list_amount`, param)
  },

  // 检测司机是否有移动仓
  checkDriver: (params) => {
    return getRequest('/warehouse/check_driver_warehouse', params)
  }
}

// 库位
interface LocationApi {
  queryList: (params?: any) => Promise<any>
  create: (params: any) => Promise<any>
  update: (params: any) => Promise<any>
  delete: (ids: string) => Promise<any>
  downloadTemplate: (params: { warehouse_id: string }) => void
  import: (params: any) => Promise<any>
}
export const locationApi: LocationApi = {
  // 库位列表
  queryList: (param) => {
    return getRequest('/warehouse_position/list', param)
  },
  // 库位新增
  create: (params) => {
    return postRequest('/warehouse_position/add', params)
  },
  // 库位编辑
  update: (params) => {
    return postRequest('/warehouse_position/edit', params)
  },
  // 库位删除
  delete: (ids) => {
    return postRequest('/warehouse_position/del', { id: ids })
  },
  // 模版下载
  downloadTemplate: (params) => {
    return getDownload('/warehouse_position/export_template', params)
  },
  // 库位导入
  import: (params) => {
    return uploadRequest('/warehouse_position/import_template', params)
  }
}

// 库存
interface InventoryApi {
  queryList: (params?: any) => Promise<any>
  exportXlsx: (params?: any) => void
  batchLog: (params?: any) => Promise<any>
}
export const inventoryApi: InventoryApi = {
  // 库存列表
  queryList: (param) => {
    return getRequest('/inventory/list', param)
  },
  // 库存变动明细
  batchLog: (param) => {
    return getRequest('/inventory/batch_log', param)
  },
  // 导出
  exportXlsx: (param) => {
    return getDownload('/inventory/exportXlsx', param)
  }
}

// 预警
interface WarningApi {
  queryList: (params?: any) => Promise<any>
  exportXlsx: (params?: any) => void
}
export const warningApi: WarningApi = {
  // 预警列表
  queryList: (param) => {
    return getRequest('/warning/list', param)
  },
  // 导出
  exportXlsx: (param) => {
    return getDownload('/warning/exportXlsx', param)
  }
}

// 预警规则
interface WarningRulesApi {
  queryList: (params?: any) => Promise<any>
  delete: (params: any) => Promise<any>
  create: (params: any) => Promise<any>
  update: (params: any) => Promise<any>
  queryGoodsList: (params?: any) => Promise<any>
}
export const warningRulesApi: WarningRulesApi = {
  // 预警规则列表
  queryList: (param) => {
    return getRequest('/goods_warning/list', param)
  },
  // 删除
  delete: (params) => {
    return postRequest('/goods_warning/del', params)
  },
  // 新增
  create: (params: any) => {
    return postRequest('/goods_warning/add', params)
  },
  // 编辑
  update: (params: any) => {
    return postRequest('/goods_warning/edit', params)
  },
  // 查询商品列表
  queryGoodsList: (params?: any) => {
    return getRequest('/goods_warning/addList', params)
  }
}
